/*
 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "iccreader_client_test.h"

#include <iostream>
#include <string>
#include <gtest/gtest.h>
#include "iccreader_hilog.h"
#include "iccreader_srv_client.h"

using namespace testing::ext;
using namespace SwanLink::Finance;
using namespace OHOS;
using namespace std;

namespace {
bool g_isMock = false;
}

void IccreaderClientTest::SetUpTestCase(void)
{
}

void IccreaderClientTest::TearDownTestCase(void)
{
}

void IccreaderClientTest::SetUp(void)
{
}

void IccreaderClientTest::TearDown(void)
{
}

namespace {

/**
 * @tc.name: IccreaderClient001
 * @tc.desc: Test Iccreader interface GetDeviceInfo
 * @tc.type: FUNC
 */
HWTEST_F (IccreaderClientTest,IccreaderClient001,TestSize.Level1)
{
    ICCREADER_HILOGD(ICCREADER_TEST,"IccreaderClient::IccreaderClient001 start.");
    auto& client = IccreaderSrvClient::GetInstance();
    if (g_isMock) {
        int fd = -1;
        DeviceInfo devInfo = {};
;
        auto ret = client.GetDeviceInfo(fd,devInfo);
        ICCREADER_HILOGI(ICCREADER_TEST,"IccreaderClientTest::ret=%{public}d",ret);
        GTEST_LOG_(INFO) << "IccreaderClient::IccreaderClient001 executing, ret = " << ret;
        ASSERT_TRUE(ret == 0);
    } else {
        int fd = -1;
        DeviceInfo devInfo = {};
;
        auto ret = client.GetDeviceInfo(fd,devInfo);
        ICCREADER_HILOGI(ICCREADER_TEST,"IccreaderClientTest::ret=%{public}d",ret);
        GTEST_LOG_(INFO) << "IccreaderClient::IccreaderClient001 executing, ret = " << ret;
        ASSERT_TRUE(ret == 0);
    }
    ICCREADER_HILOGD(ICCREADER_TEST,"IccreaderClient::IccreaderClient001 end.");
}
/**
 * @tc.name: IccreaderClient002
 * @tc.desc: Test Iccreader interface IccIOCtrl
 * @tc.type: FUNC
 */
HWTEST_F (IccreaderClientTest,IccreaderClient002,TestSize.Level1)
{
    ICCREADER_HILOGD(ICCREADER_TEST,"IccreaderClient::IccreaderClient002 start.");
    auto& client = IccreaderSrvClient::GetInstance();
    if (g_isMock) {
        int fd = -1;
        IOType type = {};
        int value = -1;
;
        auto ret = client.IccIOCtrl(fd,type,value);
        ICCREADER_HILOGI(ICCREADER_TEST,"IccreaderClientTest::ret=%{public}d",ret);
        GTEST_LOG_(INFO) << "IccreaderClient::IccreaderClient002 executing, ret = " << ret;
        ASSERT_TRUE(ret == 0);
    } else {
        int fd = -1;
        IOType type = {};
        int value = -1;
;
        auto ret = client.IccIOCtrl(fd,type,value);
        ICCREADER_HILOGI(ICCREADER_TEST,"IccreaderClientTest::ret=%{public}d",ret);
        GTEST_LOG_(INFO) << "IccreaderClient::IccreaderClient002 executing, ret = " << ret;
        ASSERT_TRUE(ret == 0);
    }
    ICCREADER_HILOGD(ICCREADER_TEST,"IccreaderClient::IccreaderClient002 end.");
}
/**
 * @tc.name: IccreaderClient003
 * @tc.desc: Test Iccreader interface ApduCommand
 * @tc.type: FUNC
 */
HWTEST_F (IccreaderClientTest,IccreaderClient003,TestSize.Level1)
{
    ICCREADER_HILOGD(ICCREADER_TEST,"IccreaderClient::IccreaderClient003 start.");
    auto& client = IccreaderSrvClient::GetInstance();
    if (g_isMock) {
        int fd = -1;
        IOType type = {};
        int len = -1;
        uint8_t cmd[128] = {0};
        uint8_t cmd_out[128] = {0};
;
        auto ret = client.ApduCommand(fd,type,len,cmd,cmd_out);
        ICCREADER_HILOGI(ICCREADER_TEST,"IccreaderClientTest::ret=%{public}d",ret);
        GTEST_LOG_(INFO) << "IccreaderClient::IccreaderClient003 executing, ret = " << ret;
        ASSERT_TRUE(ret == 0);
    } else {
        int fd = -1;
        IOType type = {};
        int len = -1;
        uint8_t cmd[128] = {0};
        uint8_t cmd_out[128] = {0};
;
        auto ret = client.ApduCommand(fd,type,len,cmd,cmd_out);
        ICCREADER_HILOGI(ICCREADER_TEST,"IccreaderClientTest::ret=%{public}d",ret);
        GTEST_LOG_(INFO) << "IccreaderClient::IccreaderClient003 executing, ret = " << ret;
        ASSERT_TRUE(ret == 0);
    }
    ICCREADER_HILOGD(ICCREADER_TEST,"IccreaderClient::IccreaderClient003 end.");
}
/**
 * @tc.name: IccreaderClient004
 * @tc.desc: Test Iccreader interface CardSearch
 * @tc.type: FUNC
 */
HWTEST_F (IccreaderClientTest,IccreaderClient004,TestSize.Level1)
{
    ICCREADER_HILOGD(ICCREADER_TEST,"IccreaderClient::IccreaderClient004 start.");
    auto& client = IccreaderSrvClient::GetInstance();
    if (g_isMock) {
        int fd = -1;
        int timeout = -1;
        SearchResult result[128] = {0};
;
        auto ret = client.CardSearch(fd,timeout,result);
        ICCREADER_HILOGI(ICCREADER_TEST,"IccreaderClientTest::ret=%{public}d",ret);
        GTEST_LOG_(INFO) << "IccreaderClient::IccreaderClient004 executing, ret = " << ret;
        ASSERT_TRUE(ret == 0);
    } else {
        int fd = -1;
        int timeout = -1;
        SearchResult result[128] = {0};
;
        auto ret = client.CardSearch(fd,timeout,result);
        ICCREADER_HILOGI(ICCREADER_TEST,"IccreaderClientTest::ret=%{public}d",ret);
        GTEST_LOG_(INFO) << "IccreaderClient::IccreaderClient004 executing, ret = " << ret;
        ASSERT_TRUE(ret == 0);
    }
    ICCREADER_HILOGD(ICCREADER_TEST,"IccreaderClient::IccreaderClient004 end.");
}
/**
 * @tc.name: IccreaderClient005
 * @tc.desc: Test Iccreader interface CardStopSearch
 * @tc.type: FUNC
 */
HWTEST_F (IccreaderClientTest,IccreaderClient005,TestSize.Level1)
{
    ICCREADER_HILOGD(ICCREADER_TEST,"IccreaderClient::IccreaderClient005 start.");
    auto& client = IccreaderSrvClient::GetInstance();
    if (g_isMock) {
        int fd = -1;
;
        auto ret = client.CardStopSearch(fd);
        ICCREADER_HILOGI(ICCREADER_TEST,"IccreaderClientTest::ret=%{public}d",ret);
        GTEST_LOG_(INFO) << "IccreaderClient::IccreaderClient005 executing, ret = " << ret;
        ASSERT_TRUE(ret == 0);
    } else {
        int fd = -1;
;
        auto ret = client.CardStopSearch(fd);
        ICCREADER_HILOGI(ICCREADER_TEST,"IccreaderClientTest::ret=%{public}d",ret);
        GTEST_LOG_(INFO) << "IccreaderClient::IccreaderClient005 executing, ret = " << ret;
        ASSERT_TRUE(ret == 0);
    }
    ICCREADER_HILOGD(ICCREADER_TEST,"IccreaderClient::IccreaderClient005 end.");
}
/**
 * @tc.name: IccreaderClient006
 * @tc.desc: Test Iccreader interface RfCardActive
 * @tc.type: FUNC
 */
HWTEST_F (IccreaderClientTest,IccreaderClient006,TestSize.Level1)
{
    ICCREADER_HILOGD(ICCREADER_TEST,"IccreaderClient::IccreaderClient006 start.");
    auto& client = IccreaderSrvClient::GetInstance();
    if (g_isMock) {
        int fd = -1;
        RfCardInfo cardInfo = {};
;
        auto ret = client.RfCardActive(fd,cardInfo);
        ICCREADER_HILOGI(ICCREADER_TEST,"IccreaderClientTest::ret=%{public}d",ret);
        GTEST_LOG_(INFO) << "IccreaderClient::IccreaderClient006 executing, ret = " << ret;
        ASSERT_TRUE(ret == 0);
    } else {
        int fd = -1;
        RfCardInfo cardInfo = {};
;
        auto ret = client.RfCardActive(fd,cardInfo);
        ICCREADER_HILOGI(ICCREADER_TEST,"IccreaderClientTest::ret=%{public}d",ret);
        GTEST_LOG_(INFO) << "IccreaderClient::IccreaderClient006 executing, ret = " << ret;
        ASSERT_TRUE(ret == 0);
    }
    ICCREADER_HILOGD(ICCREADER_TEST,"IccreaderClient::IccreaderClient006 end.");
}
/**
 * @tc.name: IccreaderClient007
 * @tc.desc: Test Iccreader interface RfCardDormancy
 * @tc.type: FUNC
 */
HWTEST_F (IccreaderClientTest,IccreaderClient007,TestSize.Level1)
{
    ICCREADER_HILOGD(ICCREADER_TEST,"IccreaderClient::IccreaderClient007 start.");
    auto& client = IccreaderSrvClient::GetInstance();
    if (g_isMock) {
        int fd = -1;
;
        auto ret = client.RfCardDormancy(fd);
        ICCREADER_HILOGI(ICCREADER_TEST,"IccreaderClientTest::ret=%{public}d",ret);
        GTEST_LOG_(INFO) << "IccreaderClient::IccreaderClient007 executing, ret = " << ret;
        ASSERT_TRUE(ret == 0);
    } else {
        int fd = -1;
;
        auto ret = client.RfCardDormancy(fd);
        ICCREADER_HILOGI(ICCREADER_TEST,"IccreaderClientTest::ret=%{public}d",ret);
        GTEST_LOG_(INFO) << "IccreaderClient::IccreaderClient007 executing, ret = " << ret;
        ASSERT_TRUE(ret == 0);
    }
    ICCREADER_HILOGD(ICCREADER_TEST,"IccreaderClient::IccreaderClient007 end.");
}
/**
 * @tc.name: IccreaderClient008
 * @tc.desc: Test Iccreader interface ScanData
 * @tc.type: FUNC
 */
HWTEST_F (IccreaderClientTest,IccreaderClient008,TestSize.Level1)
{
    ICCREADER_HILOGD(ICCREADER_TEST,"IccreaderClient::IccreaderClient008 start.");
    auto& client = IccreaderSrvClient::GetInstance();
    if (g_isMock) {
        int fd = -1;
        DeviceConfig config = {};
        ResultData result = {};
;
        auto ret = client.ScanData(fd,config,result);
        ICCREADER_HILOGI(ICCREADER_TEST,"IccreaderClientTest::ret=%{public}d",ret);
        GTEST_LOG_(INFO) << "IccreaderClient::IccreaderClient008 executing, ret = " << ret;
        ASSERT_TRUE(ret == 0);
    } else {
        int fd = -1;
        DeviceConfig config = {};
        ResultData result = {};
;
        auto ret = client.ScanData(fd,config,result);
        ICCREADER_HILOGI(ICCREADER_TEST,"IccreaderClientTest::ret=%{public}d",ret);
        GTEST_LOG_(INFO) << "IccreaderClient::IccreaderClient008 executing, ret = " << ret;
        ASSERT_TRUE(ret == 0);
    }
    ICCREADER_HILOGD(ICCREADER_TEST,"IccreaderClient::IccreaderClient008 end.");
}


}